package com.lifeverse.entity.enums;

/**
 * 健康状态枚举
 */
public enum HealthStatus {
    /**
     * 健康状态 - 系统运行正常
     */
    HEALTHY("健康", 1.0),
    
    /**
     * 警告状态 - 系统有轻微问题
     */
    WARNING("警告", 0.8),
    
    /**
     * 不健康状态 - 系统有明显问题
     */
    UNHEALTHY("不健康", 0.5),
    
    /**
     * 严重状态 - 系统有严重问题
     */
    CRITICAL("严重", 0.2),
    
    /**
     * 宕机状态 - 系统不可用
     */
    DOWN("宕机", 0.0),
    
    /**
     * 未知状态 - 无法确定系统状态
     */
    UNKNOWN("未知", -1.0);

    private final String description;
    private final double healthScore;

    HealthStatus(String description, double healthScore) {
        this.description = description;
        this.healthScore = healthScore;
    }

    public String getDescription() {
        return description;
    }

    public double getHealthScore() {
        return healthScore;
    }

    /**
     * 判断是否为正常状态
     */
    public boolean isNormal() {
        return this == HEALTHY || this == WARNING;
    }

    /**
     * 判断是否需要立即关注
     */
    public boolean requiresImmediateAttention() {
        return this == CRITICAL || this == DOWN;
    }

    /**
     * 根据健康分数获取状态
     */
    public static HealthStatus fromScore(double score) {
        if (score >= 0.9) return HEALTHY;
        if (score >= 0.7) return WARNING;
        if (score >= 0.4) return UNHEALTHY;
        if (score >= 0.1) return CRITICAL;
        if (score >= 0.0) return DOWN;
        return UNKNOWN;
    }
}